package com.k.db.postgresql;

import java.util.Arrays;

public enum PostgreSQLDataTypes {
    T_BIG_INT("bigint", "int8",""),
    T_BIG_SERIAL("bigserial","serial8",""),
    T_BIT("bit","",""),
    T_BIT_VARYING("bit varying","varbit",""),
    T_BOOLEAN("boolean","varbit",""),
    T_BOX("box","",""),
    T_BYTEA("bytea","",""),
    T_CHARACTER("character ","char",""),
    T_CHARACTER_VARYING("character varying","varchar",""),
    T_CIDR("cidr","",""),
    T_circle("circle","",""),
    T_date("date","",""),
    T_double_precision("double precision","float8",""),
    T_inet("inet","",""),
    T_integer("integer","int,int4",""),
    T_interval("interval","",""),
    T_json("json","",""),
    T_jsonb("jsonb","",""),
    T_line("line","",""),
    T_lseg("lseg","","line segment on a plane"),
    T_macaddr("macaddr","","MAC (Media Access Control) address"),
    T_macaddr8("macaddr8","","MAC (Media Access Control) address (EUI-64 format)"),
    T_money("money","","currency amount"),
    T_numeric("numeric","decimal","exact numeric of selectable precision"),
    T_path("path","","geometric path on a plane"),
    T_pg_lsn("pg_lsn","","PostgreSQL Log Sequence Number"),
    T_pg_snapshot("pg_lsn","","user-level transaction ID snapshot"),
    ;

    private final String name;
    private final String aliases;
    private final String description;

    PostgreSQLDataTypes(String name, String aliases,String description) {
        this.name = name;
        this.aliases = aliases;
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public String getAliases() {
        return aliases;
    }

    public static PostgreSQLDataTypes matchName(String name) {
        return Arrays.stream(PostgreSQLDataTypes.values()).filter(itm -> itm.name.equals(name)).findFirst().orElse(null);
    }
    public static PostgreSQLDataTypes matchAlias(String alias) {
        return Arrays.stream(PostgreSQLDataTypes.values()).filter(itm -> containAlias(itm,alias)).findFirst().orElse(null);
    }

    private static boolean containAlias(PostgreSQLDataTypes itm, String alias) {
        return Arrays.asList(itm.aliases.split(",")).contains(alias);
    }
}
